package com.ipzoe.common.service;

import com.ipzoe.common.bean.entity.RoleAdminMenu;
import com.ipzoe.common.repository.RoleAdminMenuRepository;
import com.ipzoe.common.util.DefaultService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色菜单关联Service
 * <p>
 * Created 2018/01/19.
 *
 * @author pfzhang
 */
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class RoleAdminMenuService extends DefaultService<RoleAdminMenu> {

    private RoleAdminMenuRepository roleAdminMenuRepository;

    @Resource
    public void setRoleAdminMenuRepository(RoleAdminMenuRepository roleAdminMenuRepository) {
        this.roleAdminMenuRepository = roleAdminMenuRepository;
        super.setDefaultMapper(roleAdminMenuRepository);
    }

    /**
     * 根据角色ID删除角色菜单绑定对象
     *
     * @param roleId 角色ID
     */
    public void deletedByRoleId(Long roleId) {
        roleAdminMenuRepository.deletedByRoleId(roleId);
    }

    /**
     * 根据角色ID和菜单ID获取角色菜单绑定对象
     *
     * @param roleId 角色ID
     * @param menuId 菜单ID
     * @return 角色菜单绑定对象
     */
    public RoleAdminMenu selectByRoleIdAndMenuId(Long roleId, Long menuId) {
        return roleAdminMenuRepository.selectByRoleIdAndMenuId(roleId, menuId);
    }

    /**
     * 根据角色ID获取角色绑定菜单ID集合
     *
     * @param roleId 角色ID
     * @return 菜单ID集合
     */
    public List<Long> getIdListByRoleId(Long roleId) {
        return roleAdminMenuRepository.getIdListByRoleId(roleId);
    }
}
